# -*- coding: utf-8 -*-

from dataservice import svr
from PySide2.QtCore import Slot,QObject, Qt,QPoint
from UI import Ui_MainWindow
from PySide2.QtWidgets import QApplication, QMainWindow, QDesktopWidget
from PySide2.QtGui import QMouseEvent, QStandardItem, QStandardItemModel
import sys
class MainWindow(QMainWindow,Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        #去掉标题栏
        self.setWindowFlags(Qt.FramelessWindowHint) 
        #窗口居中
        self.center()
    def center(self):
        screen=QDesktopWidget().screenGeometry()#获取屏幕分辨率
        size=self.geometry()#获取窗口尺寸
        self.move((screen.width()-size.width())/2,(screen.height()-size.height())/2)#利用move函数窗口居中
    # 重写移动事件--------<
    def mouseMoveEvent(self, e: QMouseEvent):  # 重写移动事件
        self._endPos = e.pos() - self._startPos
        self.move(self.pos() + self._endPos)

    def mousePressEvent(self, e: QMouseEvent):
        if e.button() == Qt.LeftButton:
            self._isTracking = True
            self._startPos = QPoint(e.x(), e.y())

    def mouseReleaseEvent(self, e: QMouseEvent):
        if e.button() == Qt.LeftButton:
            self._isTracking = False
            self._startPos = None
            self._endPos = None
    # 重写移动事件-------->

    # 重写槽函数
    # 点击收件箱事件
    def onShoujian(self):
        self.stackedWidget.setCurrentIndex(0)
        self.lbTitle.setText("### 收件箱")
        self._list = svr.Pull()
        model = QStandardItemModel()
        for i in self._list:
            model.appendRow(QStandardItem(i.title))
        self.lvMsgs.setModel(model)
    # 点击发件箱事件
    def onFajian(self):
        self.stackedWidget.setCurrentIndex(1)
        self.lbTitle.setText("### 发件箱")
    # 点击新建邮件事件
    def onNew(self):
        self.stackedWidget.setCurrentIndex(2)
        self.lbTitle.setText("### 写邮件")
    # 点击发送邮件
    def onSendMessage(self):
        pass
    # 添加附件
    def onAdd(self):
        pass
    # 删除附件
    def onDelete(self):
        pass
    #选择联系人
    def onSelecet(self):
        pass
    #选择收件箱下拉框
    def onShoujianFilterChanged(self,s):
        pass
    #点击收件箱邮件列表以显示正文
    def onShoujianListClicked(self,index):
        #self.txtContent.setOpenLinks(True)
        self.txtContent.setOpenExternalLinks(True)
        self.txtContent.setText(svr.readMessage(self._list[index.row()]).content)
    #选择发件箱下拉框
    def onFajianFilterChanged(self,s):
        pass
    #点击发件箱邮件列表以显示正文
    def onFajianListClicked(self,index):
        pass
app = QApplication([])
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
